package com.zhz.thymeleafdemo.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zhz.thymeleafdemo.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

//@Mapper
public interface UserMapper extends BaseMapper<User> {
    @Select("select * from user where name=#{name}")
    public User getUserByName(@Param("name")String name);

    @Select("select u.*,d.id d_id,d.dname from user u , dept d " +
            "where d.id = u.deptId order by u.id desc")
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "name",property = "name"),
            @Result(column = "password",property = "password"),
            @Result(column = "email",property = "email"),
            @Result(column = "gender",property = "gender"),
            @Result(column = "deptId",property = "deptId"),
            @Result(column = "birth",property = "bitrh")
    })
    public List<User> queryUserList();

    @Update("<script>" +
            " update user "+
            "<set> " +
            "<if test=\"name != null\">name = #{name},</if>" +
            "<if test=\"password != null\">password = #{password},</if>" +
            "<if test=\"email != null\">email = #{email},</if>" +
            "<if test=\"gender != null\">gender = #{gender},</if>" +
            "<if test=\"birth != null\">birth = #{birth},</if>" +
            "</set>"+
            "where id=#{id}"+
            "</script>")
    public User updateUser(User user);
}
